<template>
	<div class="admin_home">
		<div style="height: 200px;">
		</div>
		<div class="login">
			<div>
				<p>后台管理系统登录页</p>
				<input v-model="user.username" placeholder="请输入账号" />
				<input v-model="user.password" placeholder="请输入密码" />
				<p><button @click="login()"><div class="aaa"><h2>登录</h2></div></button></p>

			</div>
		</div>
	</div>
</template>

<script>
	export default {
		name: 'AdminLogin',
		data() {
			return {
				user: {},
			}
		},
		methods: {
			login() {
				console.log("kv=" + this.user);
				this.$postKv("/api/login", this.user)
					.then((resp) => {
						console.log(resp.data);
						let token = resp.data.data.token;
						window.localStorage.setItem("token", token);
						if(resp.data.code!=200){
							alert('账号或密码错误请重新登录')
						}
						this.$get("/api/user/info")
							.then((resp) => {
								console.log(resp.data.data)
								if (resp.data.data.role != 'adm') {
									alert('请使用管理员账号登录')
								}
								window.localStorage.setItem("token", token);
								this.user = resp.data.data
								console.log("user" + this.user);
								let date = new Date()
								window.localStorage.setItem("time", date.getFullYear()+'年'+(date.getMonth()+1)+'月'+date.getDay()+'日');
								this.$router.push("/adm")
							})
					});
			}
		},
		mounted() {

		}
	}
</script>

<style>
	.admin_home {
		background-color: #fffae8;
		margin: 0px;
		padding: 0px;
		width: 100%;
		height: 800px;
	}

	.login {
		height: 20rem;
		margin: 0 auto;
		width: 50%;
		background-color: #DCDCDC;
		border: #aaa49f 1px solid;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.login p {
		margin-top: 10%;
		font-size: 15px;
		text-align: center;
	}

	.login input {
		margin-top: 10%;
		display: flex;
		height: 3rem;
		width: 100%;
	}
	.aaa{
		background-color: #515961;
		width: 10rem;
		height: 1.7rem;
	}
</style>
